package com.qf.smsplatform.interfaces.controller;

import com.qf.smsplatform.common.util.IpUtil;
import com.qf.smsplatform.interfaces.InterfaceApplication;
import com.qf.smsplatform.interfaces.dto.SmsDTO;
import com.qf.smsplatform.interfaces.service.InterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * projectName: smsplatform
 *
 * @author: MaTianWei
 * time: 2021/8/10 16:08
 * description:映射下行接口的Controller
 */
@RestController
public class InterfaceController {

    @Autowired
    private InterfaceService interfaceService;

    /**
     * 下行接口
     * @param smsDTO    客户端请求参数
     * @param request   为了获取IP地址
     */
    @RequestMapping("/smsInterface")
    public void smsInterface(@RequestBody SmsDTO smsDTO, HttpServletRequest request){
       //获取客户端真实的IP地址
       String ip = IpUtil.getClientIpByReq(request);
       //将IP封装到DTO
        smsDTO.setIp(ip);
        //调用Service对参数进行校验
        interfaceService.checkSmsParam(smsDTO);
        //操作成功
        System.out.println(1);
    }
}
